import React, { Component } from 'react';
import './App.css'
import axios from 'axios'
export default class App extends Component {
  constructor(props){
    super(props);
    this.state = {
      music:[]
    }
  }
  render() {
    return (
      <div className="app">
        {this.state.music.map(item=>{
          return(
            <div className="item" key={item}>
                  <img src={item.coverImgUrl} className="pic" alt="" />
                  <p className="name" onClick={this.handleClick}>{this.handleTitle(item.name)}</p>
            </div>
          )
        })}
      </div>
    );
  }
  componentDidMount(){
    axios.get("http://47.97.6.61:11148/top/playlist?cat=华语").then(res=>{
      this.setState({music:res.data.playlists})
    })
  }

  handleTitle(value){
    if (value.length > 6) {
        return value.slice(0, 6) + "..."
    }
    return value;
  }
  handleClick=()=>{ //
    console.log(this)
    //this.setState({
      //msg:"change"
    //})
  }
}
